import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2023-03-16
 * Time: 21:09
 */
//内存可见性导致线程不安全
public class ThreadDemo {
     volatile   public static   int flag=0;
    public static void main(String[] args) {
        Thread t1=new Thread(()->{
            while(flag==0){
                //为空
            }
            System.out.println("循环结束,t1线程结束");
        });
        Thread t2=new Thread(()->{
            Scanner scanner=new Scanner(System.in);

            flag=scanner.nextInt();

        });
        t1.start();
        t2.start();
    }
}
